﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Lead2012.Business
{
    public class FieldSystemRepository
    {
        // Create an instance of entity
        Lead2012Entities entities = new Lead2012Entities();

        public List<FieldSystem> GetAll()
        {
            return (from c in entities.FieldSystems select c).ToList();
        }
        
        public FieldSystem GetSingle(int id)
        {
            return (from _object in entities.FieldSystems where _object.FieldId == id select _object).FirstOrDefault();
        }

        public void Create(FieldSystem _object)
        {
            entities.AddToFieldSystems(_object);
            entities.SaveChanges();
        }

        public void Update(FieldSystem _object)
        {
            entities.SaveChanges();
        }
        public void Delete(int id)
        {
            var _object = (from _list in entities.FieldSystems where _list.FieldId == id select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }
        public void Save(FieldSystem _object)
        {
            _object.EntityKey = (from FieldSystem ac in entities.FieldSystems where ac.FieldId == _object.FieldId select ac).FirstOrDefault().EntityKey;
            entities.SaveChanges();
        }
    }
}